package com.luhui;

import com.intellij.execution.impl.ConsoleViewUtil;
import com.intellij.execution.ui.ConsoleView;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.EditorFactory;
import groovy.ui.ConsoleTextEditor;
import org.apache.velocity.runtime.directive.Foreach;
import org.jetbrains.builtInWebServer.ConsoleManager;

import java.io.IOException;

/**
 * Created with LXD
 *
 * @author:Luhui
 * @qq:729913162
 * @Date:2018-08-03
 * @Time:9:29
 */
public class SearchOnConsoleAction extends AnAction {


    @Override
    public void actionPerformed(AnActionEvent e) {
        Editor[] editors =  EditorFactory.getInstance().getAllEditors();
        for (Editor editor : editors) {
            if(ConsoleViewUtil.isConsoleViewEditor(editor)){
                String selectText = editor.getSelectionModel().getSelectedText();
                if(selectText!=null && !selectText.trim().equals("")){
                    try {
                        Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler https://www.baidu.com/s?wd="+selectText);
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }
                }

            }
        }
    }
}
